#include <iostream>
#include <vector>
#include <cstdio>
#include <unistd.h>
#include "Thread.hpp"

using namespace ThreadMoudle;

void Print(const std::string &name)
{
    int cnt = 1;
    while (true)
    {
        std::cout << name << "is running, cnt: " << cnt++ << std::endl;
        sleep(1);
    }
}
// 管理原生线程->转变为对数组的增删查改

const int gnum = 10;

int main()
{
    std::vector<Thread> threads;
    for (int i = 0; i < gnum; i++)
    {
        std::string name = "thread-" + std::to_string(i + 1);
        threads.emplace_back(name, Print);
        sleep(1);
    }
    // 同一启动
    for (auto thread : threads)
    {
        thread.Start();
    }
    sleep(10);
    // 同一结束
    for (auto &thread : threads)
    {
        thread.Stop();
    }
    // 线程等待
    for (auto &thread : threads)
    {
        thread.Join();
    }
     return 0;
}